<template>
  <div>
    <h1>App组件</h1>
    {{ count }}
    <hr />
    <Child ref="childComp" />
  </div>
</template>

<script>
import Child from "@/components/Child";
export default {
  name: "App",
  components: { Child },
  data() {
    return {
      count: 0,
    };
  },
    mounted() {
    //初始化的时候，在这里对某一个子组件绑定自定义事件
    this.$refs.childComp.$once("changeCount", this.changeCount);
    // this.$refs.childComp.$on("changeCount", this.changeCount);
  },
  methods: {
    changeCount(value) {
      console.log(value);
      this.count += value;
    },
  },
};
</script>

<style></style>
